<?php
session_start();
include '../conn.php'; // 确保这是正确的路径到你的数据库连接文件

// 检查是否设置了所有必要的参数
if (!isset($_REQUEST['uid']) || !isset($_REQUEST['gid'])) {
    echo "非法访问！";
    exit;
}
$uid = $_REQUEST['uid'];
// print_r($uid);
$gid = $_REQUEST['gid'];
// print_r($gid);
$content = $_REQUEST['content'];
// print_r($content);
// 检查用户是否存在
$sql = "SELECT * FROM user WHERE id = " . $uid;
$result = $conn->query($sql);
// 用户存在才能进行评论
if ($result && $result->num_rows > 0) {
	// 返回评论列表
	$sql2 = "select * from comment where good_id = ".$gid;
	if ($conn->query($sql2)) {
		$comments = array();
		$result2 = $conn->query($sql2);
		while ($comment = $result2->fetch_assoc()) {
		    $comments[] = $comment;
		}
		// print_r($comments);
		// 返回所有评论数据
		echo json_encode($comments);
		$conn->close();
	  }else {
		echo "评论失败";
		$conn->close();
	  }
	
} else {
    echo "没有找到用户或查询失败";
}
?>
